package designpattern.proxy.jdk;

import java.io.IOException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * @author zhangxin
 * @date 2020/10/29
 */
public class JdkProxyTest {

    public static void main(String[] args) throws IOException {

        MyServiceImpl myServiceImpl = new MyServiceImpl();

        InvocationHandler proxyHandler = new MyInvocationHandler(myServiceImpl);

        MyService proxyInstance = (MyService) Proxy.newProxyInstance(MyService.class.getClassLoader(),
                new Class[] { MyService.class},
                proxyHandler);

        proxyInstance.test("Java");


        ProxyUtils.generateClassFile(myServiceImpl.getClass(), "MyServiceImplProxy");


        System.out.println("-----------------");
        // 泛型代理Java
        MyService myService = new MyInvocationHandlerGen<MyServiceImpl>().newInstance(myServiceImpl);
        myService.test("泛型代理 java ");


    }
}
